
<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class folderViewfolder extends JView
{
   
	// Overwriting JView display method
	function display($tpl = null) 
	{
        $model = $this->getModel();
        $user_name = jfactory::getUser()->username;
        //$this->folders = $this->treeFolders($model->getAllFolders($user_name), '|___ ');
      
        $this->setLayout('default');

        $this->mainFolders = $model->getMainFolders($user_name);

        $this->folders = $model->getFolders($user_name);
        
		parent::display();
	}
    
    public function treeFolders($folders, $stringPrefix = '|_ '){
    	$listFolder = array();
        foreach($folders as $fol){
            $listFolder[$fol->FOME_PARENT][] = $fol;
        }
        
        $folders = array();
        foreach($listFolder[0] as $fol){
            $folders[] = $fol;
            if($listFolder[$fol->FOME_CODE]){
                foreach($listFolder[$fol->FOME_CODE] as $f){
                    $f->FOME_NAME = $stringPrefix.$f->FOME_NAME;
                    $folders[] = $f;
                }
            }
            
        }
        
        return $folders;
    }
}


